// pages/goods_provide/index.js
var app = getApp();//引用app.js
var commonURL = app.data.baseURL;
var commonURLYY = app.data.newURL;
var commonURLXX = app.data.lastURL;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    selectarea: '请选择小区',
    grouperName: '',
    phoneNum: '',
    weichat: '',
    fans: '',
    explain: '',
    xiaoqu: '',
    xiaoquValue:''
  },
  grouperName: function (e) {
    console.log(e)
    this.setData({
      grouperName: e.detail.value
    })
  },
  xiaoquValue:function(e){
    this.setData({
      xiaoquValue: e.detail.value
    })
  },
  phoneNum: function (e) {
    console.log(e)
    this.setData({
      phoneNum: e.detail.value
    })
  },
  weichat: function (e) {
    console.log(e)
    this.setData({
      weichat: e.detail.value
    })
  },
  explain: function (e) {
    console.log(e)
    this.setData({
      explain: e.detail.value
    })
  },
  fans: function (e) {
    console.log(e)
    this.setData({
      fans: e.detail.value
    })
  },
  formsubmit: function (e) {
    console.log(e.detail.value)
    let obj = this.data
    console.log(obj)
    if (!obj.grouperName || obj.grouperName=='') {
      wx.showToast({
        icon: 'none',
        title: '请填写团长姓名',
      })
      return
    } else if (!obj.phoneNum || obj.phoneNum == '') {
      wx.showToast({
        icon: 'none',
        title: '请填写团长电话',
      })
      return
    } else if (!obj.xiaoquValue  || obj.xiaoquValue == '') {
      wx.showToast({
        icon: 'none',
        title: '请填写小区名称',
      })
      return
    } else if (!obj.weichat || obj.weichat == '') {
      wx.showToast({
        icon: 'none',
        title: '请填写微信号',
      })
      return
    } 
    let that = this
    wx.request({
      url: commonURL + 'op=area_commander_apply',
      data: {
        name: obj.grouperName,
        mobile: obj.phoneNum,
        wechatnum: obj.weichat,
        fansnumber: obj.fans,
        openid: obj.openid,
        unionId: app.data.unionId || wx.getStorageSync('unionId'),
        remark: obj.xiaoquValue
      },
      success: function (res) {
        console.log(res.data)
        if (res.data.status == 1) {
          wx.showModal({
            title: '提示',
            content: '提交成功,请耐心等待',
            showCancel: false,
            success: function (res) {
              wx.navigateBack()
            }
          })
        } else {
          wx.showModal({
            title: '提示',
            content: res.data.msg,
            showCancel: false,
            success: function (res) {
              wx.navigateBack()
            }
          })
        }
      }
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this
    wx.request({
      url: commonURL + 'op=get_arealist',
      data: { uniacid: app.data.GZHid, state: 1 },
      header: {
        'content-type': 'application/json'
      },
      success: function (res) {
        var casArray = []
        var xiaoqu = []
        for (var i = 0; i < res.data.list.length; i++) {
          casArray.push(res.data.list[i].name)
          xiaoqu.push({ name: res.data.list[i].name, id: res.data.list[i].id })
        }
        console.log(casArray, xiaoqu)
        that.setData({
          casArray: casArray,
          xiaoqu: xiaoqu
        })
      }
    })
    wx.getStorage({
      key: 'openid',
      success: function (res) {
        console.log(res)
        that.setData({
          openid: res.data
        })
      },
    })
  },
  bindCasPickerChange: function (e) {
    console.log('选的是', this.data.casArray[e.detail.value])
    if (e.detail.value == 4) {
      this.setData({ reply: true })
    } else {
      this.setData({ reply: false })
    }
    this.setData({
      casIndex: e.detail.value,
      selectarea: this.data.casArray[e.detail.value]
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },
})